from typing import Optional
from decimal import Decimal
from sqlmodel import SQLModel, Field
from datetime import datetime


class OrderDetail(SQLModel, table=True):
    """订单明细模型 - 对应文档2表结构"""
    __tablename__ = "order_detail"

    # 主键字段
    id: Optional[str] = Field(primary_key=True, description="主键ID")
    ord_detl_code: Optional[str] = Field(default=None, description="订单明细代码")
    stroom_id: Optional[str] = Field(default=None, description="仓库ID")
    his_entp_code: Optional[str] = Field(default=None, description="医院企业代码")
    entp_name: Optional[str] = Field(default=None, description="企业名称")
    prod_name: Optional[str] = Field(default=None, description="产品名称")
    spec: Optional[str] = Field(default=None, description="规格")
    pac: Optional[str] = Field(default=None, description="包装")
    his_drug_id: Optional[str] = Field(default=None, description="医院药品ID")
    medins_name: Optional[str] = Field(default=None, description="医疗机构名称")
    shp_time: Optional[datetime] = Field(default=None, description="发货时间")
    invo_date: Optional[datetime] = Field(default=None, description="发票日期")
    purc_price: Optional[Decimal] = Field(default=None, description="进货价格")
    purc_amt: Optional[Decimal] = Field(default=None, description="进货金额")
    shp_amt: Optional[Decimal] = Field(default=None, description="发货金额")
    shp_cnt: Optional[Decimal] = Field(default=None, description="发货数量")
    pubonln_pric: Optional[Decimal] = Field(default=None, description="公开线上价格")
    disc_rate: Optional[Decimal] = Field(default=None, description="折扣率")
    shp_stas: Optional[str] = Field(default=None, description="发货状态")
    is_capacity: Optional[str] = Field(default=None, description="是否容量")
    itemname: Optional[str] = Field(default=None, description="项目名称")
    invono: Optional[str] = Field(default=None, description="发票号码")
    drug_unino: Optional[str] = Field(default=None, description="药品唯一编号")
    his_ord_no: Optional[str] = Field(default=None, description="医院订单号")
    inc_num: Optional[str] = Field(default=None, description="包含数量")
    transform_num: Optional[Decimal] = Field(default=None, description="转换数量")
    his_shpp_cnt: Optional[Decimal] = Field(default=None, description="医院发货数量")
    shpp_amt: Optional[Decimal] = Field(default=None, description="发货金额2")
    entp_shp_no: Optional[str] = Field(default=None, description="企业发货号")
    his_unique_key: Optional[str] = Field(default=None, description="医院唯一键")
    his_stroom_addr: Optional[str] = Field(default=None, description="医院仓库地址")
    shpp_time: Optional[datetime] = Field(default=None, description="发货时间2")
    shp_detl_no: Optional[str] = Field(default=None, description="发货明细号")
    ver: Optional[str] = Field(default=None, description="版本")
    created_at: Optional[datetime] = Field(default=None, description="创建时间")
    updated_at: Optional[datetime] = Field(default=None, description="更新时间")

    __all__ = ["OrderDetail"]